<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>jd2</title>
    <style>
        ul li {
            list-style: none;
            margin: 10px;
        }

        .li {
            width: 300px;
            height: 30px;
            text-align: center;

        }

        .classA {
            background-color: rgb(0, 55, 128);
        }
    </style>
</head>

<body>
    <div id="app">
        <ul>
            <li v-for="(item,index) in lesson">
                <div class="li" v-on:click='fn(index)' v-bind:class="[item.falg? 'classA': 'classB']"> 
                    {{item.name}}{{item.sz}}</div>
            </li>

        </ul>
        <hr>
        <p>Total:{{bool}}</p>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <script type="text/javascript">
        var vm = new Vue({
            el: '#app',
            data: {
                bool: 0,
                lesson: [
                    { name: 'Web Decelopment', falg: false, sz: 3000 },
                    { name: 'Python', falg: false, sz: 1000 },
                    { name: 'java', falg: false, sz: 2000 },
                    { name: 'GO', falg: false, sz: 2200 },
                ],
            },
            methods: {
                fn: function (number) {
                    for (var i = 0; i < this.lesson.length; i++) {
                        if (number == i) {
                            this.lesson[i].falg = !this.lesson[i].falg;
                            if (this.lesson[i].falg === true) {
                                this.bool += this.lesson[i].sz

                            } else {
                                this.bool -= this.lesson[i].sz
                            } }
                    }}
            }
        })
    </script>
</body>

</html>